import copy
import datetime
from time import sleep

import requests
import  login_info.login_info as login
from selenium import webdriver
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from tools.get_sql import getsql,get_all_dict,get_small_dict,trim_num_full,trim_num_small,del_total
class river_table_info_1():
    def __init__(self):
        self.emr_user = login.emr_user
        self.emr_password = login.emr_password
        self.get_cookie_url = login.river_get_cookie_url
        self.get_brower_cookies()
    def get_brower_cookies(self):
        chrome_options = webdriver.ChromeOptions()
        # chrome_options.add_argument('--headless')
        # chrome_options.add_argument('--disable-gpu')
        # chrome_options.add_argument('--no-sandbox')
        # chrome_options.add_argument('--hide-scrollbars')
        browser = webdriver.Chrome(options=chrome_options)

        element = browser.find_element_by_css('div[class*="loadingWhiteBox"]')
        browser.execute_script("arguments[0].click();", element)

        browser.implicitly_wait(5)
        browser.get(self.get_cookie_url)
        # print(browser.page_source)

        WebDriverWait(browser, 10).until(EC.visibility_of(browser.find_element_by_id('login-by')))
        login_name = browser.find_element_by_id('login-by')
        login_name.send_keys(self.emr_user)
        WebDriverWait(browser, 10).until(EC.visibility_of(browser.find_element_by_id('password')))
        login_psd = browser.find_element_by_id('password')
        login_psd.send_keys(self.emr_password)

        login_btn = browser.find_element_by_id('btn-submit-login')
        login_btn.click()

        simi = browser.find_element_by_id('details-button')
        simi.click()
        go = browser.find_element_by_id('proceed-link')
        go.click()
        WebDriverWait(browser, 10).until(EC.visibility_of(browser.find_element_by_class_name('ExhibitionCard___1iXkH')))
        go_in = browser.find_element_by_xpath('//*[@id="root"]/div/div/div/div/div[2]/div[2]/div/div/div/div[4]/div')
        go_in.click()
        sleep(6)
        WebDriverWait(browser, 10).until(EC.visibility_of(browser.find_element_by_link_text('数据地图')))
        print('find')

        map_in = browser.find_element_by_link_text('数据地图')
        map_in.click()
        WebDriverWait(browser, 10).until(EC.visibility_of(browser.find_element_by_xpath('//*[@id="root"]/div/div/div[2]/div[3]/div/div/div[1]/div/div/div/div[1]/span[1]/input')))
        print('find_search_bardige')
        input = browser.find_element_by_xpath('//*[@id="root"]/div/div/div[2]/div[3]/div/div/div[1]/div/div/div/div[1]/span[1]/input')
        input.send_keys('ods_cz_per_item_cc')
        WebDriverWait(browser, 10).until(EC.visibility_of(browser.find_element_by_xpath('//*[@id="root"]/div/div/div[2]/div[3]/div/div/div[1]/div/div/div/div[1]/span[1]/span/button')))
        search_button = browser.find_element_by_xpath('//*[@id="root"]/div/div/div[2]/div[3]/div/div/div[1]/div/div/div/div[1]/span[1]/span/button')
        browser.find_elements_by_css_selector()
        search_button.click()
        sleep(20)
    def put_cookies_in_txt(self,cookie):
        f = open("studio_cookie.txt", "w")
        cookie = str(cookie)
        f.write(cookie)
if __name__ == '__main__':
    a = river_table_info_1()
